package com.MinesweeperGame.server;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;


public class LocalPersistanceManager
{
       private PersistenceManager persistenceManager;

       private final PersistenceManagerFactory PMF =
               JDOHelper.getPersistenceManagerFactory("transactions-optional");
       
       private static LocalPersistanceManager instance;

       public static PersistenceManager getPersistenceManager(){

    	   if(instance == null){
    		   instance = new LocalPersistanceManager();
    	   }
    	   
    	   return instance.getPersistenceManger();
    	   
       }
       
       private LocalPersistanceManager(){
    	   
    	   
       }
       
       private PersistenceManager getPersistenceManger(){
    	   
    	   if(persistenceManager == null)
               persistenceManager =  PMF.getPersistenceManager();

	       if(persistenceManager.isClosed())
	               persistenceManager =  PMF.getPersistenceManager();
	
	       return persistenceManager;
       }
       

       
}


